/**
 * 
 */
package com.nari.interfaces.action;

import java.math.BigDecimal;
import java.math.RoundingMode;

import org.apache.struts2.json.JSONUtil;
import org.apache.struts2.json.annotations.JSON;

import com.nari.coreframe.action.struts2.JSONActionSupport;
import com.nari.interfaces.model.IMissionFailureLog;
import com.nari.interfaces.service.IMissionFailureLogService;
import com.nari.platform.model.PageCond;
import com.nari.platform.model.ResponseMsg;
import com.nari.platform.model.ResultWithPageCond;
import com.opensymphony.xwork2.Action;

/**
 * 
 * @author Xiaopeng
 * @date 2013-12-8
 */
public class MissionFailureLogAction extends JSONActionSupport {
	private static final long serialVersionUID = -5985339060337232396L;
	private IMissionFailureLogService iMissionFailureLogService;
	//任务审计日志查询
	private String measureMeterNo;
	private String startDate;
	private String endDate;
	//分页查询
	private int pageIndex = 1; // 默认查询第一页列表
	private PageCond pageCond;
	private int pageSize;
	private ResultWithPageCond<IMissionFailureLog> missionLogPage;
	//日志管理
	private String missionLogUID;
	
	/**
	 * 上传任务审计日志查询
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-12-9
	 */
	public String queryMissionLogPage() throws Exception {
		// 分页信息
		this.pageCond = new PageCond();
		int start = (this.pageIndex - 1) * this.pageCond.getLimit();
		this.pageCond.setStart(start);
		// 分页结果
		this.missionLogPage = iMissionFailureLogService.queryAuditLogPage(measureMeterNo, startDate, endDate, pageCond);
		// 计算结果集的页数
		this.pageSize = new BigDecimal(this.missionLogPage.getPageCond().getTotal())
				.divide(new BigDecimal(this.missionLogPage.getPageCond().getLimit()), RoundingMode.UP).intValue();
		if (pageSize == 0) pageSize = 1;
		return "logPage";
	}
	
	/**
	 * 删除任务日志
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-12-9
	 */
	public String deleteMissionLogByUID() throws Exception {
		if(missionLogUID!=null && !"".equals(missionLogUID)) {
			this.iMissionFailureLogService.deleteEntityById(missionLogUID);
		}
		this.rmsg = ResponseMsg.getInstance(true, "");
		this.writeJsonStrToResponse(JSONUtil.serialize(rmsg));
		return Action.SUCCESS;
	}

	/**
	 * @return the iMissionFailureLogService
	 */
	@JSON(serialize=false)
	public IMissionFailureLogService getiMissionFailureLogService() {
		return iMissionFailureLogService;
	}

	/**
	 * @param iMissionFailureLogService the iMissionFailureLogService to set
	 */
	public void setiMissionFailureLogService(
			IMissionFailureLogService iMissionFailureLogService) {
		this.iMissionFailureLogService = iMissionFailureLogService;
	}

	/**
	 * @return the measureMeterNo
	 */
	public String getMeasureMeterNo() {
		return measureMeterNo;
	}

	/**
	 * @param measureMeterNo the measureMeterNo to set
	 */
	public void setMeasureMeterNo(String measureMeterNo) {
		this.measureMeterNo = measureMeterNo;
	}

	/**
	 * @return the startDate
	 */
	public String getStartDate() {
		return startDate;
	}

	/**
	 * @param startDate the startDate to set
	 */
	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	/**
	 * @return the endDate
	 */
	public String getEndDate() {
		return endDate;
	}

	/**
	 * @param endDate the endDate to set
	 */
	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	/**
	 * @return the pageIndex
	 */
	public int getPageIndex() {
		return pageIndex;
	}

	/**
	 * @param pageIndex the pageIndex to set
	 */
	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	/**
	 * @return the pageCond
	 */
	public PageCond getPageCond() {
		return pageCond;
	}

	/**
	 * @param pageCond the pageCond to set
	 */
	public void setPageCond(PageCond pageCond) {
		this.pageCond = pageCond;
	}

	/**
	 * @return the pageSize
	 */
	public int getPageSize() {
		return pageSize;
	}

	/**
	 * @param pageSize the pageSize to set
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * @return the missionLogPage
	 */
	public ResultWithPageCond<IMissionFailureLog> getMissionLogPage() {
		return missionLogPage;
	}

	/**
	 * @param missionLogPage the missionLogPage to set
	 */
	public void setMissionLogPage(
			ResultWithPageCond<IMissionFailureLog> missionLogPage) {
		this.missionLogPage = missionLogPage;
	}

	/**
	 * @return the missionLogUID
	 */
	public String getMissionLogUID() {
		return missionLogUID;
	}

	/**
	 * @param missionLogUID the missionLogUID to set
	 */
	public void setMissionLogUID(String missionLogUID) {
		this.missionLogUID = missionLogUID;
	}

}
